﻿using Gallery.DAL.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Gallery
{
    public partial class Gallery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }


        private void LoadData()
        {
           
                var list = PictureRepository.FindAll().ToList();

                foreach (var item in list)
                {
                   String link ="~/Files/" + item.PictureId.ToString() + "_" + item.FileName;
                   String title = String.Format("Name: {0} , Created: {1}, Author Age: {2}",
                       item.PictureName, item.DateCreated == null ? "unknown" : item.DateCreated.Value.ToShortDateString(), item.AuthorAge);  

                    HyperLink h = new HyperLink();
                    h.CssClass = "fancybox-thumbs";
                    h.Attributes.Add("title", title);
                    h.Attributes.Add("data-fancybox-group", "thumb");
                    h.NavigateUrl = link;

                    Image img = new Image();
                    img.CssClass = "imgSmall";
                    img.ImageUrl = link;
                    img.AlternateText = item.PictureName;

                    h.Controls.Add(img);
                    pnlContainer.Controls.Add(h);   
                }
          
        }

    }
}